﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Composite
{
  public interface IBox
    {
        void Say();
        void Add(IBox box);
        void Remove();
    }

    public interface IOperation
    {
       
    }

    public class SingleBox : IBox
    {
        public void Add(IBox box)
        {
            throw new NotImplementedException();
        }

        public void Remove()
        {
            throw new NotImplementedException();
        }

        public void Say()
        {
            Console.WriteLine("Say ..... lalala ");
        }
    }

    public class ContentBox : IBox
    {
        private List<IBox> lsBox = new List<IBox>();



        public void Add(IBox box)
        {
            lsBox.Add(box);
        }

        public void Remove()
        {
            if (lsBox.Count>0)
            {
                lsBox.RemoveAt(0);
            }
        }

        public void Say()
        {
            // 自己的代码

            foreach (var item in lsBox)
            {
                item.Say();
            }
        }
    }
}
